﻿
-- =============================================
-- Author:		zengfei
-- Create date: 02m/23/2012
-- Description:	操作其他收入表
-- =============================================
Create PROCEDURE [dbo].[Usp_ModifyOtherIncome]
	@p_Action	char,				-- A:新增, C:修改, D:删除
	@p_BillNo	varchar(30),
	@p_Account	varchar(30),
	@p_FeeSubjectNo	int,
	@p_Amount	numeric(15,2),
	@p_Department	int,
	@p_Employee	varchar(20),
	@p_ReceiveDate	datetime,
	@p_EntryDate	datetime,
	@p_Remark	varchar(100),
	@p_RecordID	int out,
	@p_ErrMsg	varchar(100) out,
	@p_RFlag	smallint out
AS
if	@p_Action = 'A'
begin
	if	exists (select * from OtherIncome where BillNo = @p_BillNo)
	begin
		raiserror('其他收入单据编号[%s]重复!', 16, 1, @p_BillNo)
		goto ErrHandle
	end
	
	insert into OtherIncome (BillNo, Account, FeeSubjectNo, Amount, Department, Employee, ReceiveDate, EntryDate, Remark)
		values (@p_BillNo, @p_Account, @p_FeeSubjectNo, @p_Amount, @p_Department, @p_Employee, @p_ReceiveDate, @p_EntryDate, @p_Remark)
	
	if	@@ERROR <> 0 or @@ROWCOUNT = 0 goto ErrHandle
	
	select @p_RecordID = @@IDENTITY 
end
else if	@p_Action = 'C'
begin
	update OtherIncome set Account = @p_Account, 
						FeeSubjectNo = @p_FeeSubjectNo, 
						Amount = @p_Amount,
						Department = @p_Department,
						Employee = @p_Employee,
						ReceiveDate = @p_ReceiveDate,
						EntryDate = @p_EntryDate,
						Remark = @p_Remark 
					where RecordID = @p_RecordID 
	
	if	@@ERROR <> 0 or @@ROWCOUNT = 0 goto ErrHandle
end
else if	@p_Action = 'D'
begin
	Delete from OtherIncome where RecordID = @p_RecordID 
	
	if	@@ERROR <> 0 or @@ROWCOUNT = 0 goto ErrHandle
end

set @p_RFlag = 1

ErrHandle:
set @p_RFlag = -1

